package handler

import (
	"fmt"

	"github.com/micro/go-log"

	db "git.oschina.net/zhufeng9282/go-micro-study/srv/user/db"
	account "git.oschina.net/zhufeng9282/go-micro-study/srv/user/proto"
	"golang.org/x/net/context"
)

type Account struct{}

func (a *Account) Create(ctx context.Context, req *account.CreateRequest, rsp *account.CreateResponse) error {
	log.Log("Received create request", req)
	user := db.User{Username: req.User.Username, Password: req.Password, Nickname: req.User.Nickname}
	fmt.Println("c", user)
	id := db.CreateUser(&user)
	fmt.Println("ok id: ", id)
	rsp.Errcode = 0
	rsp.Errmsg = "ok"
	return nil
}

func (a *Account) Login(ctx context.Context, req *account.LoginRequest, rsp *account.LoginResponse) error {
	log.Log("Received create request", req)
	rsp.Errcode = 1
	rsp.Errmsg = "ok"
	return nil
}
